import {
  getScrollViewTop,
  setScrollViewTop
} from "./util"

const scrollTopMixin = {
  data() {
    return {
      mixinScrollTop: 0
    }
  },
  beforeDestroy() {
    setScrollViewTop(0)
  },
  onShow() {
    const scrollTop = getScrollViewTop()
    if (scrollTop) {
      this.mixinScrollTop = scrollTop
    }
  },
  methods: {
    onScroll({
      target: {
        scrollTop
      }
    }) {
      setScrollViewTop(scrollTop)
    },
  }
}

export default scrollTopMixin